// 堰闸 chart
var weirgatesChartOption = {
	chart: {
		zoomType: 'x'
	},
	exporting: {
		enabled: true
	},
	xAxis: {
		type: 'datetime',
		dateTimeLabelFormats: {
			day: '%m-%d',
			week: '%m-%d',
			month: '%y-%m-%d',
			year: '%y-%m-%d'
		}
	},
	yAxis: [{
		title: {
			text: '水位(mm)',
		},
		lineWidth: 1,

	}, {
		title: {
			text: '流量(m³/s)'
		},
		lineWidth: 1,
		opposite: true
	}],
	credits: {
		enabled: false
	},
	legend: {

		align: 'center',
		verticalAlign: 'bottom',
		borderWidth: 1
	},
	plotOptions: {
		series: {
			marker: {
				enabled: false
			}
		}
	},
	tooltip: {
		shared: true,
		crosshairs: true,
		dateTimeLabelFormats: {
			second: '%m-%d %H:%M',
			minute: '%m-%d %H:%M',
			hour: '%m-%d %H:%M',
			day: '%m-%d',
			week: '%m-%d',
			month: '%y-%m-%d',
			year: '%y-%m-%d'
		}
	}
}

function buildWeirgatesChart(windowVals, tabPanel) {
	var id = tabPanel.attr('id');
	var bTm = windowVals.startTime;
	var eTm = windowVals.endTime;
	var dxn = windowVals.dxn;
	var stcd = tabPanel.data('stcd');
	var splitBTm = bTm.split('-');
	var startDate = new Date(splitBTm[0], splitBTm[1] - 1, splitBTm[2]);
	var chartParams = {};
	var windowType = '';
	if (id == 'day') {
		chartParams.url = '../gis/WeirgatesScreen.json?method=getSingleStatDayProcessByGisJs';
		chartParams.chartTitle = '逐日8时水位过程';
		chartParams.seriesData = [{
			type: 'spline',
			name: '水位',
			color: 'green',
			dataVal: 'vals'
		}, {
			type: 'spline',
			name: '警戒水位',
			color: '#FF0000',
			dataVal: 'totalVals'
		}, {
			type: 'spline',
			name: '流量',
			color: '#00E3E3',
			dataVal: 'values5',
			yAxis: 1,
			visible: false
		}, {
			type: 'spline',
			name: '多年同期',
			color: '#FFFF37',
			dataVal: 'values1',
			visible: false
		}, {
			type: 'spline',
			name: '典型年',
			color: '#FF00FF',
			dataVal: 'values6',
			visible: false
		}];
		windowType = 'water';
	} else if (id == 'hour') {
		chartParams.url = '../gis/WeirgatesScreen.json?method=getSingleStatHourProcessByGisJs';
		chartParams.chartTitle = '实时水位过程';
		chartParams.seriesData = [{
			type: 'spline',
			name: '水位',
			color: 'green',
			dataVal: 'vals'
		}, {
			type: 'spline',
			name: '流量',
			color: '#FF0000',
			dataVal: 'values2',
			yAxis: 1
		}];
		windowType = 'water-Weirgates';
	}
	chartParams.subChartTitle = bTm + '至' + eTm;

	var sendParams = {
		bTm: bTm,
		eTm: eTm,
		stcd: stcd,
		dxn: dxn,
		r: new Date().getTime()
	};

	buildChart(tabPanel, startDate, riverChartOption, chartParams, sendParams, id, windowType);
}


function buildWeirgatesTable(windowVals, tabPanel) {
	var id = tabPanel.attr('id');
	var stcd = tabPanel.data('stcd');
	var dxn = windowVals.dxn;
	var startTime = windowVals.startTime;
	var endTime = windowVals.endTime;

	var sendParams = {
		bTm: startTime,
		eTm: endTime,
		stcd: stcd,
		dxn: dxn,
		r: new Date().getTime()
	};
	var params = $.extend({}, windowVals);
	if (id == 'day') {
		params.csvDataHeaders = '序号,日期,水位(m),多年同期水位(m),典型年水位(m),流量(m³/s)';
		params.dataKeys = ['tm', 'val', 'value1', 'value6', 'value5'];

		params.dataIndex = ['maxWater', 'minWater', 'curAvgWater', 'maxFlow', 'minFlow', 'curAvgFlow'];
		params.fDataIndex = ['hisMaxWater', 'hisMinWater', 'hisAvgWater', 'hisMaxFlow', 'hisMinFlow', 'hisAvgFlow'];
		params.sotrHistory = ['maxWaterSort', 'minWaterSort', 'avgWaterSort', 'maxFlowSort', 'minFlowSort', 'avgFlowSort'];
		params.maxMinAvg = ['waterMaxs', 'waterMins', 'waterAvgs', 'flowMaxs', 'flowMins', 'flowAvgs'];
		params.plMaxDateName = ['最高水位', '最低水位', '平均水位', '最大流量', '最小流量', '平均流量'];
		params.warnDayNumKey = 'warDayNum';
		params.cols = [6, 10];

		params.chartDataTableUrl = '../gis/WeirgatesScreen.json?method=getSingleStatDayProcess';
		params.analysisTableUrl = '../gis/WeirgatesScreen.json?method=getDayProcessAnalysis';
	} else if (id == 'hour') {
		params.csvDataHeaders = '序号,日期,水位(m),流量(m³/s)';
		params.dataKeys = ['tm', 'val', 'value2'];

		params.chartDataTableUrl = '../gis/WeirgatesScreen.json?method=getSingleStatHourProcess';
	}
	buildTable(tabPanel, params, sendParams, id, 'water');
}

function windowWeirgatesQuery(event) {
	var showTabPanel = event.data.panel;
	var windowVals = getWindowVals(showTabPanel, true, false);
	buildWeirgatesChart(windowVals, showTabPanel);
	buildWeirgatesTable(windowVals, showTabPanel);
}